package com.learning.jquizenglish.common.controller;

import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.learning.jquizenglish.R;
import com.learning.jquizenglish.common.fragment.JQuizEnglishFragment;

public class HeaderBarQuiz implements OnClickListener {

	private View root;
	protected Fragment mFrag;
	public HeaderBarQuiz(Fragment frag){
		mFrag = frag;
	}
	
	public View onCreateHeaderView(LayoutInflater inflater,
			ViewGroup container) {
		root = inflater.inflate(R.layout.header_bar_default, container,false);
		root.findViewById(R.id.layoutBack).setOnClickListener(this);
		root.findViewById(R.id.imgComment).setOnClickListener(this);
		root.findViewById(R.id.imgHelp).setOnClickListener(this);
		return root;
	}
	
	public void showMoreButton(){
		root.findViewById(R.id.layoutMore).setVisibility(View.VISIBLE);
	}

	public void hideMoreButton(){
		root.findViewById(R.id.layoutMore).setVisibility(View.GONE);
	}
	
	private void back(){
		mFrag.getActivity().onBackPressed();
	}
	
	private void showComment(){
		if (mFrag instanceof JQuizEnglishFragment) {
			((JQuizEnglishFragment)mFrag).onComment();
		}
	}
	
	private void showHelp(){
		if (mFrag instanceof JQuizEnglishFragment) {
			((JQuizEnglishFragment)mFrag).onHelp();
		}
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.layoutBack:
			back();
			break;
		case R.id.imgComment:
			showComment();
			break;
		case R.id.imgHelp:
			showHelp();
			break;
		default:
			break;
		}
	}
}
